<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <canvas id="canvas" style="border: 1px solid #aaa; display: block; margin: 50px auto;">
        当前浏览器不支持Canvas，请更换浏览器
    </canvas>
    <script>
        window.onload = function () {
            var canvas = document.getElementById("canvas");

            canvas.width = 800;
            canvas.height = 800;

            var context = canvas.getContext("2d");

            context.font = 'bold 40px Arial';

            context.fillStyle = '#058';

            context.fillText('欢迎大家学习《Canvas绘图接口详解》！', 40, 100);
            context.lineWidth = 1;

            context.strokeStyle = '#058';
            context.strokeText("欢迎大家学习《Canvas绘图接口详解》！", 40, 200);

            context.fillText('欢迎大家学习《Canvas绘图接口详解》！', 40, 300, 400);
            context.strokeText("欢迎大家学习《Canvas绘图接口详解》！", 40, 400, 400);

            var linearGrad = context.createLinearGradient(0, 0, 800, 0);
            linearGrad.addColorStop(0.0, 'red');
            linearGrad.addColorStop(0.25, 'orange');
            linearGrad.addColorStop(0.5, 'yellow');
            linearGrad.addColorStop(0.75, 'green');
            linearGrad.addColorStop(1.0, 'purple');

            context.fillStyle = linearGrad;
            context.fillText("欢迎大家学习《Canvas绘图接口详解》！", 40, 500);

            var backgroundImage = new Image();
            backgroundImage.src = 'brick-s.png';
            backgroundImage.onload = function () {
                var pattern = context.createPattern(backgroundImage, 'repeat');
                context.fillStyle = pattern;
                context.font = 'bold 100px Arial';
                context.fillText('Canvas!', 40, 650);
                context.strokeText('Canvas!', 40, 650);
            }
        }

    </script>
</body>
</html>